package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findListByPage(Long userId, Integer pageNum, Integer pageSize) {
        //创建一个分页条件对象
        IPage page= new Page(pageNum,pageSize);

        //查询到的分页结果
        page = blackListMapper.findBlackList(page, userId);
        //构建返回对象
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }


    public void deleteByUserIdAndBlackUserId(Long userId, Long blackUserId) {
        //构造条件
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        //where user_id =? and black_user_id = ?
        wrapper.eq("user_id",userId).eq("black_user_id",blackUserId);
        blackListMapper.delete(wrapper);
    }
}
